package www.qiyue.execl;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletRequest;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.*;

@Controller
public class Excel {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @PostMapping(value = "uploadss")
    @ResponseBody
    public String uploadExcel(HttpServletRequest request) throws Exception {

        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;

        MultipartFile file = multipartRequest.getFile("filename");
        if (file.isEmpty()) {
            return "文件不能为空";
        }
        InputStream inputStream = file.getInputStream();
        List<List<Object>> list = util.parseExcel(inputStream, file.getOriginalFilename());
        inputStream.close();
        for (int i = 0; i < list.size(); i++) {
            List<Object> lo = list.get(i);
            for (int j = 0; j < lo.size(); j++) {

            }
        }
        return null;
    }

    @GetMapping("index")
    public String test() {
        return "index";
    }
    public void writeToXls(Map<String,String> map)throws Exception{
        String adress = map.get("adress");
        String user_name = map.get("user_name");
        String star_date = map.get("star_date");
        String end_date = map.get("end_date");
        String code = map.get("code");
        String bz = map.get("bz");
        String sql="INSERT into extest VALUES(null,'"+code+"','"+adress+"','"+user_name+"','"+star_date+"','"+end_date+"','"+bz+"')";
        jdbcTemplate.update(sql);
    }

    public static void main(String[] args) {
        ArrayList<String> strings = new ArrayList<>();

        System.out.println(strings);
    }

}
